<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  // function Mon(name, age) {
  //   this.name = name
  //   this.age = age
  // }
  // Mon.prototype = {

  // }
  // es6引入了类的概念，创建一个class类，里面都会有一个构造函数方法
  class Monkey {
    constructor(name, age) {
      this.name = name
      this.age = age
      this.like = function () {
        console.log('水蜜桃')
      }
    }
    showName(eat) {
      console.log(this.name + "喜欢吃" + eat)
    }
    // 相当于
    // Monkey.prototype.showName = function(){}
  }

  let sun = new Monkey('孙悟空', 200)
  sun.like()
  console.log(sun.name)
  sun.showName('桃子')

  // 继承 extends
  class Sunwukong extends Monkey {
    constructor(name, age, color) {
      // super() 使用extend必须使用super来调用父类的构造方法
      super(name, age)
      this.color = color
    }
    showName(eat) {
      super.showName(eat)
    }
    showColor() {
      console.log('颜色是' + this.color)
    }
  }

  let wuk = new Sunwukong('美猴王', 500, '黄色')
  wuk.showColor()
  wuk.showName('桃')
</script>

</html>